home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / athena / zephyr / dist / src.zwgc.zwgc.el < prev    next >
Encoding:
Text File  |  1989-10-16  |  5.7 KB  |  182 lines

  1. ; zwgc.el
  2. ;
  3. ; This file is part of the Project Athena Zephyr Notification System.
  4. ; Created by: Mark W. Eichin <eichin@athena.mit.edu>
  5. ; $Source: /mit/zephyr/src/zwgc/RCS/zwgc.el,v $
  6. ; $Author: jtkohl $
  7. ; Copyright (c) 1988 by the Massachusetts Institute of Technology.
  8. ; For copying and distribution information, see the file
  9. ; "mit-copyright.h". 
  10. ;
  11. ; Emacs mode for running zwgc in a sub process of emacs. It pops up a
  12. ; window for every new message; if you make bells appear between each
  13. ; message, it will be able to seperate them. If you move the mouse
  14. ; into the message window and hit `delete' it will delete the current
  15. ; message; if there are other messages, it will show them, if not, it
  16. ; will make the window go away.
  17. ;
  18. ; Invoke with M-x zwgc.
  19. ; Also included is M-x zsend, which prompts for a user name and a
  20. ; message to send to them. If the message is blank, a buffer is popped
  21. ; up to edit the message in. If a prefix argument is given, zsend
  22. ; prompts for an instance instead. If the user name is blank, the last
  23. ; one is reused.
  24. ; The following should be added to your .zephyr.desc file if you want
  25. ; to take advantage of the zwgc message seperation features:
  26. ;    does $mode
  27. ;    match tty
  28. ;        beep
  29. ;    endmatch
  30. ;    enddoes
  31. ;
  32. (defvar zwgc_el-RCS-id)
  33. (setq zwgc_el-RCS-id "$Header: zwgc.el,v 1.3 89/07/07 19:03:32 jtkohl Exp $")
  34. ;
  35. ;
  36.  
  37. (defun narrow-to-string (str)
  38.   "narrow and put up a string..."
  39.   (interactive "sString: ")
  40.   (narrow-to-region (point) (point))
  41.   (insert str))
  42.  
  43. (defvar zwgc-prog "/usr/etc/zwgc" 
  44.   "*Program to run as the zwgc process. Should set it for the machine type.")
  45.  
  46. (defun zwgc-wakeup (proc string)
  47.   "Procedure called when zwgc spits something out"
  48.   (save-excursion (set-buffer (get-buffer "*zwgc*"))
  49.           (goto-char (point-max))
  50.           (if (= 7 (string-to-char string))
  51.               (progn
  52.             (ding 1)
  53.             (message "got one!")
  54.             (narrow-to-string string))
  55.             (insert string)))
  56.   (Special-pop-up-window (get-buffer "*zwgc*"))
  57.   )
  58.  
  59. (defun zwgc ()
  60.   "emacs mode for running zwgc in a sub process of emacs. It pops up a
  61. window for every new message; if you make bells appear between each
  62. message, it will be able to seperate them. If you move the mouse into
  63. the message window and hit `delete' it will delete the current
  64. message; if there are other messages, it will show them, if not, it
  65. will make the window go away."
  66.   (interactive)
  67.   (require 'shell)
  68.   (let ((buffer (get-buffer-create "*zwgc*")) proc status)
  69.     (setq proc (get-buffer-process buffer))
  70.     (if proc
  71.     (setq status (process-status proc)))
  72.     (save-excursion
  73.       (set-buffer buffer)
  74.       (if (memq status '(run stop))
  75.       nil
  76.     (if proc (delete-process proc))
  77.     (setq proc (start-process "Zwgc" buffer 
  78.                   zwgc-prog "-ttymode" "-nofork"))
  79.     (set-process-filter proc 'zwgc-wakeup))
  80.       (shell-mode)
  81.       (local-set-key "\177" 'zwgc-punt)
  82.       )
  83.     ))
  84.  
  85.  
  86. (defun Special-pop-up-window (buffer &optional max-height)
  87.   "Pop up a window that is just big enough to hold the current buffer."
  88.   (interactive "bBuffer to pop: ")
  89.   (let* ((retwin (selected-window))
  90.      (pop-up-windows t)
  91.      (window-min-height 1))
  92.     (pop-to-buffer buffer)
  93.     (setq lines (1+ (count-lines (point-min) (point-max))))
  94.     (enlarge-window (- lines (window-height (selected-window))))
  95.     (goto-char (point-min))
  96.     (other-window 1)
  97.     ))
  98.  
  99. (defun zwgc-punt ()
  100.   "Delete the current ZephyrGram from the *zwgc* buffer."
  101.   (interactive)
  102.   (let ((window-min-height 1))
  103.     (display-buffer (get-buffer "*zwgc*"))
  104.     (delete-region (point-min) (point-max))
  105.     (widen)
  106.     (if (not (search-backward "\007" nil t))
  107.     (delete-windows-on "*zwgc*")
  108.       (narrow-to-region (point) (point-max))
  109.       (enlarge-window (- (1+ (count-lines (point-min) (point-max)))
  110.              (window-height (selected-window))))
  111.       (goto-char (point-min))
  112.       )))
  113. ;;
  114. ;; [eichin:19880309.2005EST]
  115. ;; zsend.el
  116. ;; Send zephyrgrams from emacs...
  117. ;;
  118.  
  119. (defvar *who* "" "last user sent to with zsend")
  120.  
  121. (defun zsend (&optional who message)
  122.   "zsend prompts for a user name and a message to send to them as a
  123. ZephyrGram. If the message is blank, a buffer is popped up to edit the
  124. message in. If a prefix argument is given, zsend prompts for an
  125. instance instead. If the user name is blank, the last one is reused."
  126.   (interactive
  127.    (list (if current-prefix-arg        ; is this portable???
  128.          (cons 'instance (read-input "Instance:"))
  129.        (cons 'who (read-input "Who:")))
  130. ;     (select-window (minibuffer-window))
  131. ;     (enlarge-window 4)
  132.      (read-input "Message:")))
  133.   (save-excursion
  134.     (let ((tempbuf (get-buffer-create " *zephyr*send*")))
  135.       (switch-to-buffer tempbuf)
  136.       (local-set-key "\C-c\C-c" 'exit-recursive-edit)
  137.       (erase-buffer)
  138.       (if (and (equal (cdr who) "")
  139.            (equal *who* ""))
  140.       (message "Please specify user at least once.")
  141.     (if (not (equal (cdr who) ""))
  142.         (setq *who* who)        ; save *who* for next time
  143.       (setq who *who*))        ; or, use the old value
  144.     (if (not (equal message ""))
  145.         (progn
  146.           (insert message)
  147.           (zwrite who))
  148.       (progn
  149.         (recursive-edit)
  150.         (zwrite who)))))))
  151.  
  152.  
  153. (defun zwrite (who)
  154.   "Send a ZephyrGram to user WHO, zsend is the user interface to this."
  155.   (if (eq 'who (car who))
  156.       (call-process-region (point-min) (point-max) ;range
  157.                "/usr/athena/zwrite" ;process
  158.                t        ;delete-p
  159.                t        ;output-p
  160.                nil        ;redisplay-p
  161.                "-a"        ; jtkohl is being a twit
  162.                "-q"        ;args
  163.                (cdr who))
  164.     (call-process-region (point-min) (point-max) ;range
  165.                "/usr/athena/zwrite" ;process
  166.                t        ;delete-p
  167.                t        ;output-p
  168.                nil        ;redisplay-p
  169.                "-a"        ; jtkohl is being a twit
  170.                "-q"        ;args
  171.                "-i"        ;[eichin:19880312.0015EST]
  172.                (cdr who)))
  173.   (if (not (equal (point-max) 1))
  174.       (message (buffer-substring 1 (1- (point-max))))))
  175.  
  176. ; suggested binding (control-meta-z)
  177. ;(global-set-key "\M-\C-z" 'zsend)
  178.  
  179.  
  180.